package com.mg.case1;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {

    @Test
    public void testHashSet() {
        Set<Person> set = new HashSet<Person>();

        Person p1 = new Person(11, 1, "张三");
        Person p2 = new Person(12, 1, "李四");
        Person p3 = new Person(11, 1, "张三");
        Person p4 = new Person(11, 1, "李四");

        //只验证p1、p3
        System.out.println("p1 == p3 ? : " + (p1 == p3));
        System.out.println("p1.equals(p3) ? : "+p1.equals(p3));
        System.out.println("-----------------------分割线--------------------------");
        set.add(p1);
        set.add(p2);
        set.add(p3);
        set.add(p4);
        System.out.println("set.size() = "+set.size());
    }

    @Test
    public void testHashMap() {
        Map<Person, Person> map = new HashMap<>();

        Person p1 = new Person(11, 1, "张三");
        Person p2 = new Person(12, 1, "李四");
        Person p3 = new Person(11, 1, "张三");
        Person p4 = new Person(11, 1, "李四");

        //只验证p1、p3
        System.out.println("p1 == p3 ? : " + (p1 == p3));
        System.out.println("p1.equals(p3) ? : "+p1.equals(p3));
        System.out.println("-----------------------分割线--------------------------");

        map.put(p1, p1);
        map.put(p2, p2);
        map.put(p3, p3);
        map.put(p4, p4);

        System.out.println("map.size() = "+ map.size());
    }
}